package com.yilijk.base.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DataUtils {

    public static final String Type1 = "yyyy-MM-dd HH:mm:ss";
    public static final String Type2 = "yyyy-MM-dd HH:mm";
    public static final String Type3 = "yyyy-MM-dd ";
    public static final String Type4 = "HH:mm:ss";
    public static final String Type5 = "HH:mm";
    public static final String Type6 = "MM-dd";

    /**
     * 时间转换   时间戳 - 字符串
     * @param l
     * @param type
     * @return
     */
    public static String long2string(long l,String type){
        String date = new SimpleDateFormat(type).format(l);
        return date;
    }

    /**
     * 时间转换  字符串 - 时间戳
     * @param s
     * @param type
     * @return
     */
    public static long string2long(String s,String type){
        Long timestamp = null;
        try {
            timestamp = new SimpleDateFormat(type).parse(s).getTime();
        }catch (ParseException e){
            e.printStackTrace();
        }
        return timestamp;
    }

}
